import { SET_PROFILE} from '../types/counter'
//, SET_SHOW_MPQRCODE
import { createAction } from 'redux-actions'
import {getUserInfo} from '../../api/api'

// export const asyncInc = createAction(ASYNC_INCREMENT, () => {
//   return new Promise(resolve => {
//     setTimeout(() => {
//       resolve(1)
//     }, 1000)
//   })
// })
export const getProfile = createAction(SET_PROFILE, () => {
  return new Promise((resolve, reject) => {

    getUserInfo()
      .then(response => {
        if (!response.data) {
          // 由于mockjs 不支持自定义状态码只能这样hack
          // dispatch('LogOut')
          reject('请先登陆')
        }
        const data = response.data

        if (data.User.Roles && data.User.Roles.length > 0) {
          // 验证返回的roles是否是一个非空数组
          // commit('SET_ROLES', data.User.Roles)
        } else {
          reject('getInfo: roles must be a non-null array !')
        }
        // commit('SET_PROFILE', data)
        // commit('SET_NAME', data.User.UserName)
        // commit('SET_AVATAR', data.User.Avatar)
        // commit('SET_INTRODUCTION', data.User.introduction)
        resolve(response)
      })
      .catch(error => {
        reject(error)
      })
     
  })
})
// export const getShowMpQrcode = createAction(SET_SHOW_MPQRCODE, () => {
//   return new Promise(resolve => {
//     commit('SET_SHOW_MPQRCODE', visible)
//         resolve()
//   })
// })